package com.ml.mall.api.variant;

import com.ml.mall.annotations.OperLog;
import com.ml.mall.api.BaseController;
import com.ml.mall.bean.base.ApiRestResult;
import com.ml.mall.bean.req.variant.*;
import com.ml.mall.consts.PermissionConst;
import com.ml.mall.enums.RetStatusNum;
import com.ml.mall.service.variant.SysProductVariantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
* <p>
*  前端控制器
* </p>
*
* @author kyyang
* Created 2021-05-15
*/

@Api(tags = "【product】产品下实体")
@RestController
@RequestMapping("/variant")
public class SysProductVariantController extends BaseController {

     @Autowired
     private SysProductVariantService sysProductVariantService;


    @RequestMapping(method = RequestMethod.POST, path = "/query_one")
    @ApiOperation("查询实际产品详情")
//    @RequiresPermissions(PermissionConst.VARIANT_QUERY_ONE)
    public ApiRestResult sysProductVariantQueryOne(@RequestBody @Valid VariantQueryOneReq variantQueryOneReq) {
        return ApiRestResult.ok( sysProductVariantService.sysProductVariantByQueryOne(variantQueryOneReq));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/query_all")
    @ApiOperation("查询所有实际产品")
//    @RequiresPermissions(PermissionConst.VARIANT_QUERY_ALL)
    public ApiRestResult sysProductVariantQueryAll(@RequestBody @Valid VariantQueryAllReq variantQueryAllReq) {
        return ApiRestResult.ok( sysProductVariantService.sysProductVariantQueryAll(variantQueryAllReq));
    }


    @RequestMapping(method = RequestMethod.POST, path = "/new")
    @OperLog(operDesc = "实际产品新增", operModul = "variant", operType = "new")
    @ApiOperation("实际产品新增")
//    @RequiresPermissions(PermissionConst.VARIANT_NEW)
    public ApiRestResult sysProductVariantNew(@Valid @RequestBody VariantNewReq req ) {
        int i = sysProductVariantService.sysProductVariantNew(req);
        return ApiRestResult.ok(i);
    }

    @RequestMapping(method = RequestMethod.POST, path = "/edit")
    @OperLog(operDesc = "实际产品编辑", operModul = "variant", operType = "edit")
    @ApiOperation("实际产品编辑")
//    @RequiresPermissions(PermissionConst.VARIANT_EDIT)
    public ApiRestResult sysProductVariantEdit(@Valid @RequestBody VariantEditReq req ) {
        int i = sysProductVariantService.sysProductVariantEdit(req);
        return ApiRestResult.ok(i);
    }


    @RequestMapping(method = RequestMethod.POST, path = "/del")
    @OperLog(operDesc = "实际产品删除", operModul = "variant", operType = "del")
    @ApiOperation("实际产品删除")
//    @RequiresPermissions(PermissionConst.VARIANT_DEL)
    public ApiRestResult sysProductVariantDel(@RequestParam(value = "ids") List<Long> ids) {
        if(ids==null||ids.size()<1){
            return ApiRestResult.err(RetStatusNum.PARAMS_ERROR.getMessage(), RetStatusNum.PARAMS_ERROR.getCode());
        }
        int i = sysProductVariantService.sysProductVariantDel(ids);
        return ApiRestResult.ok(i);
    }


    @RequestMapping(method = RequestMethod.POST, path = "/sales/new")
    @OperLog(operDesc = "sku限时价格新增", operModul = "variant/sales", operType = "new")
    @ApiOperation("sku限时价格新增")
//    @RequiresPermissions(PermissionConst.VARIANT_SALES_NEW)
    public ApiRestResult sysProductVariantSalesNew(@Valid @RequestBody VariantSalesNewReq req ) {
        int i = sysProductVariantService.sysProductVariantSalesNew(req);
        return ApiRestResult.ok(i);
    }


    @RequestMapping(method = RequestMethod.POST, path = "/sales/edit")
    @OperLog(operDesc = "sku限时价格编辑", operModul = "variant/sales", operType = "edit")
    @ApiOperation("sku限时价格编辑")
//    @RequiresPermissions(PermissionConst.VARIANT_SALES_EDIT)
    public ApiRestResult sysProductVariantSalesEdit(@Valid @RequestBody VariantSalesEditReq req ) {
        int i = sysProductVariantService.sysProductVariantSalesEdit(req);
        return ApiRestResult.ok(i);
    }

    @RequestMapping(method = RequestMethod.POST, path = "/recommend/new")
    @OperLog(operDesc = "新增推荐产品", operModul = "variant/sales", operType = "edit")
    @ApiOperation("新增推荐产品")
//    @RequiresPermissions(PermissionConst.VARIANT_RECOMMEND_NEW)
    public ApiRestResult sysProductVariantRecommendNew(@Valid @RequestBody VariantSalesEditReq req ) {
        int i = sysProductVariantService.sysProductVariantSalesEdit(req);
        return ApiRestResult.ok(i);
    }

    @RequestMapping(method = RequestMethod.POST, path = "/VariantState/edit")
    @OperLog(operDesc = "修改实体状态", operModul = "variant", operType = "edit")
    @ApiOperation("修改实体状态")
//    @RequiresPermissions(PermissionConst.VARIANT_VARIANT_STATE_EDIT)
    public ApiRestResult sysProductVariantStateEdit(@Valid @RequestBody VariantStateEditReq req ) {
        int i = sysProductVariantService.sysProductVariantStateEdit(req);
        return ApiRestResult.ok(i);
    }
}
